﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace SignalBox.Core.Model
{
    public class TrackText
    {

        public string Text
        {
            get;
            set;
        }

        public Font Font
        {
            get;
            set;
        }

        public Color Color
        {
            get;
            set;
        }

        public Point Location
        {
            get;
            set;
        }

        public SizeF Size
        {
            get;
            set;
        }

        public static List<TrackText> FromXml(XElement e)
        {
            List<TrackText> result = (from XElement lbl in e.Elements("Label")
                                      select new TrackText()
                                      {
                                           Font = SignalBox.Core.Data.FontConverter.FromBase64String(lbl.Element("Font").Value),
                                           Text = lbl.Element("Text").Value,
                                           Location = new Point(Int32.Parse(lbl.Element("X").Value), Int32.Parse(lbl.Element("Y").Value)),
                                           Color = Color.FromArgb(Int32.Parse(lbl.Element("Color").Value))

                                      }).ToList();
            return result;
        }

        public XElement ToXML()
        {

            return new XElement("Label", 
                new XElement("Font", SignalBox.Core.Data.FontConverter.ToBase64String(Font)),
                new XElement("Text", Text),
                new XElement("X", Location.X),
                new XElement("Y", Location.Y),
                new XElement("Color", Color.ToArgb())
                );

        }
    }
}
